<template>
    <div class="recover-password">
        <div class="wid-1200">
            <div class="login-logo">
                <i><img src="@/assets/images/logo.png"></i>
                <div>
                    已有账号？
                    <router-link to="/login">登录</router-link>
                </div>
            </div>
            <div class="main-box">
                <ul class="process-box">
                    <li v-for="(item , index) in processList" :key="index" :class="{active:isActive == index}">
                        <span>{{index+1}}</span>
                        <b>
                            <Icon type="md-checkmark" color="#fff" size="20"/>
                        </b>
                        <p>{{item.title}}</p>
                    </li>
                </ul>
                <div class="content-box">
                    <!--注册填写信息-->
                    <div class="form-box" v-show="isActive == 0">
                        <Form ref="formCustom" :model="formCustom" :rules="ruleCustom" :label-width="80">
                            <FormItem label="用户名" prop="name">
                                <Input v-model="formCustom.name" placeholder="请输入用户名"/>
                            </FormItem>
                            <FormItem label="登录密码" prop="passwd">
                                <Input type="password" v-model="formCustom.passwd" placeholder="请输入密码"/>
                            </FormItem>
                            <FormItem label="确认密码" prop="passwdCheck">
                                <Input type="password" v-model="formCustom.passwdCheck" placeholder="请确认密码"/>
                            </FormItem>
                            <FormItem label="手机号码" prop="tel">
                                <Input v-model="formCustom.tel" placeholder="请输入手机号码"/>
                            </FormItem>
                            <FormItem>
                                <Checkbox v-model="formCustom.isRead">我已阅读并同意《温榆河公园服务协议》</Checkbox>
                            </FormItem>
                            <FormItem>
                                <Button type="warning" :disabled="!formCustom.isRead" long size="large"
                                        @click="handleSubmit('formCustom')">同意条款并注册
                                </Button>
                                <!--<button :disabled="!formCustom.isRead" class="submit-btn" @click="handleSubmit('formCustom')">同意条款并注册</button>-->
                            </FormItem>
                        </Form>
                        <p class="prompt">6-18位，区别大小写，字母、数字、特殊符号中的两种或两种以上</p>
                    </div>
                    <!--填写手机验证码-->
                    <div class="form-box" v-show="isActive == 1">
                        <Form ref="formCaptcha" :model="formCaptcha" :rules="ruleCaptcha" :label-width="80">
                            <FormItem label="手机号">
                                {{formCaptcha.tel}}
                            </FormItem>
                            <FormItem label="验证码" prop="captchaNum">
                                <div class="code-box">
                                    <Input v-model="formCaptcha.captchaNum" placeholder="请输入验证码"/>
                                    <button>获取验证码</button>
                                </div>
                            </FormItem>
                            <FormItem>
                                <Button type="warning" long size="large"  @click="captchaSubmit('formCaptcha')">提交
                                </Button>
                            </FormItem>
                        </Form>
                    </div>
                    <!--注册成功-->
                    <div class="result-box" v-show="isActive == 2">
                        <div class="result-title">
                            <Icon type="ios-checkmark-circle-outline" size="32" color="#58AB6B" />
                            <span>注册成功!</span>
                        </div>
                        <div class="result-content">
                            <p>登录名：{{formCustom.name}}</p>
                            <p>绑定手机：{{formCustom.tel}}</p>
                        </div>
                    </div>
                </div>
            </div>
            <footer>
                copyright 温榆河湿地公园2019-2020c
            </footer>
        </div>

    </div>
</template>

<script>
    //iview
    import {Icon, Form, Input, FormItem, Checkbox, Button} from "view-design";

    export default {
        components: {Icon, Form, Input, FormItem, Checkbox, Button},
        data() {
            //确认验证
            const validatePassCheck = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请再次输入你的密码'));
                } else if (value !== this.formCustom.passwd) {
                    callback(new Error('两个输入密码不匹配！'));
                } else {
                    callback();
                }
            };
            //验证码验证
            const captchaCheck = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('验证码不能为空'));
                }  else if (value !== '3521') {
                    callback(new Error('验证码错误！'));
                } else {
                    callback();
                }
            };
            return {
                isActive:0,//显示结果
                processList: [
                    {title: '填写注册信息'},
                    {title: '接受并填写验证码'},
                    {title: '填写注册信息'},
                ],
                formCustom: {
                    passwd: '',
                    passwdCheck: '',
                    tel: '',
                    name: '',
                    isRead: false
                },
                formCaptcha:{
                    captchaNum:'',//验证码
                    tel:''
                },
                ruleCustom: {
                    passwd: [
                        {required: true,  message: '密码不能为空', trigger: 'blur'}
                    ],
                    passwdCheck: [
                        {required: true, validator: validatePassCheck, trigger: 'blur' }
                    ],
                    name: [
                        {required: true, message: '用户名不能为空', trigger: 'blur'}
                    ],
                    tel: [
                        {required: true, message: '手机号码不能为空', trigger: 'blur'}
                    ]
                },
                ruleCaptcha:{
                    captchaNum: [
                        {required: true,validator: captchaCheck, trigger: 'blur'}
                    ],
                }
            }
        },
        methods: {
            //填写注册信息 提交
            handleSubmit(name) {
                console.log(this.formCustom.isRead)
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        console.log('Success!');
                        this.isActive = 1
                        this.formCaptcha.tel = this.formCustom.tel
                    } else {
                        console.log('Fail!');
                    }
                })
            },
            //验证码提交
            captchaSubmit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        console.log('Success!');
                        this.isActive = 2
                    } else {
                        console.log('Fail!');
                    }
                })
            }
        }
    }
</script>

<style lang="scss" scoped>

    @import "@/assets/css/basis";
    .main-box {
        min-height: calc(100vh - 132px);
    }
    .login-logo {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 1200px;
        height: 70px;
        margin: 0 auto;

        img {
            width: 126px;
        }
        div{
            line-height: 26px;
            color: #666;
            font-size: 14px;
            a{
                display: inline-block;
                width:60px;
                height:26px;
                margin-left: 10px;
                border:1px solid rgba(204,204,204,1);
                border-radius:2px;
                color: #666;
                text-align: center;
            }
        }
    }

    .process-box {
        position: relative;
        display: flex;
        justify-content: center;
        padding: 20px 0;
        text-align: center;

        &:before {
            content: '';
            position: absolute;
            left: 0;
            right: 0;
            top: 38px;
            width: 100%;
            height: 1px;
            z-index: -1;
            background-color: #e5e5e5;
        }

        li {
            width: 246px;
            position: relative;
            z-index: 1;

            &.active {
                span {
                    display: none;
                }

                b {
                    display: block;
                    width: 30px;
                    height: 30px;
                    margin: 3px auto;
                    border-radius: 15px;
                    text-align: center;
                    line-height: 30px;
                    color: #fff;
                    background-color: $colorGreen;
                }

                &:before {
                    content: '';
                    position: absolute;
                    left: 0;
                    top: 18px;
                    width: 100%;
                    height: 2px;
                    z-index: -1;
                    background-color: $colorGreen;
                }
                p{
                    font-weight: bold;
                    color: $colorGreen;
                }
            }

            b {
                display: none;
            }

            span {
                display: block;
                width: 30px;
                height: 30px;
                margin: 3px auto;
                border-radius: 15px;
                text-align: center;
                line-height: 30px;
                color: #fff;
                background-color: #ccc;
            }
            p{
                margin-top: 10px;
                font-size: 18px;
                color: #999;
            }

        }
    }

    .form-box {
        width: 382px;
        margin: 40px auto 0;
    }

    .content-box {
        position: relative;

        .prompt {
            position: absolute;
            left: 50%;
            top: 66px;
            font-size: 12px;
            color: #999;
            transform: translateX(210px);
        }
    }

    .submit-btn {
        height: 40px;
        width: 302px;
        background: rgba(233, 176, 78, 1);
        border-radius: 2px;
        color: #fff;
    }
    .code-box {
        display: flex;
        button{
            width:102px;
            height:40px;
            margin-left: 10px;
            background:rgba(229,229,229,1);
            border-radius:2px;
            font-size: 14px;
            color: #333;
        }
    }
    .result-title {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 60px 0 40px;
        span{
            margin-left: 16px;
            font-size: 22px;
            color: #333;
        }
    }
    .result-content {
        display: flex;
        justify-content: center;
        font-size: 14px;
        color: #666;
        p{
            padding: 0 50px;
        }

    }
    footer {
        width: 100%;
        padding: 10px 0 30px;
        text-align: center;
        font-size: 14px;
        color: #666;
        border-top: 1px solid #e5e5e5;
    }
</style>

